package com.example.emos.api.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.example.emos.api.common.util.PageUtils;
import com.example.emos.api.db.dao.TbEvaluationDao;
import com.example.emos.api.db.dao.TbMarkDao;
import com.example.emos.api.db.pojo.TbExamEva;
import com.example.emos.api.db.pojo.TbExamEvaGroup;
import com.example.emos.api.service.EvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author ：Supyo
 * @date ：Created in 2021/11/16 15:03
 * @description：
 */
@Service
public class EvaluationServiceImpl implements EvaluationService {
    @Autowired
    TbEvaluationDao evaluationDao;
    @Autowired
    TbMarkDao markDao;

    @Override
    public PageUtils selectEvaluationGroup(HashMap param) {
        ArrayList<HashMap> list = evaluationDao.selectEvaluationGroup(param);
        long count = 1;
        int start = (Integer) param.get("start");
        int length = (Integer) param.get("length");
        PageUtils pageUtils = new PageUtils(list, count, start, length);
        return pageUtils;
    }

    @Override
    public int insert(TbExamEvaGroup evaGroup) {
        int rows = evaluationDao.insert(evaGroup);
        return rows;
    }

    @Override
    public int updateEvaluationGroup(HashMap param) {
        int rows = evaluationDao.updateEvaluationGroup(param);
        return rows;
    }

    @Override
    public int deleteEvaluationGroup(Integer[] ids) {
        int rows = evaluationDao.deleteEvaluationGroup(ids);
        return rows;
    }


    @Override
    public PageUtils selectEvaluationsBypages(HashMap param) {
        ArrayList<HashMap> list = evaluationDao.selectEvaluationsBypages(param);
        long count = evaluationDao.countEvaluations(param);
        int start = (Integer) param.get("start");
        int length = (Integer) param.get("length");
        PageUtils pageUtils = new PageUtils(list, count, start, length);
        return pageUtils;
    }

    @Override
    public int addEvaluations(TbExamEva eva) {
        int userId = StpUtil.getLoginIdAsInt();
        String creator = markDao.selectPersonName(userId);
        eva.setCreator(creator);
        int rows = evaluationDao.addEvaluations(eva);
        return rows;
    }

    @Override
    public int updateEvaluations(HashMap param) {
        int rows = evaluationDao.updateEvaluations(param);
        return rows;
    }

    @Override
    public int deleteEvaluations(Integer[] ids) {
        int rows = evaluationDao.deleteEvaluations(ids);
        return rows;
    }

    @Override
    public int moveEvaluations(HashMap param) {
        int rows = evaluationDao.moveEvaluations(param);
        return rows;
    }

    @Override
    public PageUtils selectEvaluationsByGroupId(HashMap param) {
        ArrayList<HashMap> list = evaluationDao.selectEvaluationsByGroupId(param);
        long count = 1;
        int start = (Integer) param.get("start");
        int length = (Integer) param.get("length");
        PageUtils pageUtils = new PageUtils(list, count, start, length);
        return pageUtils;
    }

    @Override
    public TbExamEva selectEvaluationById(Integer id) {
        TbExamEva map = evaluationDao.selectEvaluationById(id);
        return map;
    }
}
